package com.ruoyi.web.controller.teaching;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.teaching.domain.PlatformFFeedback;
import com.ruoyi.teaching.domain.dto.FrontDownRequest;
import com.ruoyi.teaching.domain.dto.feedbackFrontDownSortDTO;
import com.ruoyi.teaching.service.PlatformFFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 王旭
 * @since 2025-02-12
 */
@RestController
@RequestMapping("/platform/feedback")
@Api(tags = "platform-反馈管理")
public class PlatformFFeedbackController {
    @Autowired
    private PlatformFFeedbackService platformFFeedbackService;

    /**
     * 前台反馈中心上半部
     */
    @GetMapping("/frontUp")
    @ApiOperation(value = "前台反馈中心上半部", notes = "前台反馈中心上半部")
    public AjaxResult frontUp(Integer pageNum, Integer pageSize, Integer feedbackStatus) {
        return platformFFeedbackService.frontUp(pageNum, pageSize, feedbackStatus);
    }

    /**
     * 前台反馈中心下半部
     */
    @GetMapping("/frontDown")
    @ApiOperation(value = "前台反馈中心下半部", notes = "前台反馈中心下半部")
    public AjaxResult frontDown(Integer pageSize, Integer pageNum, Integer replySort,Integer lookSort,Integer timeSort,String title,Integer feedbackStatus) {
        return platformFFeedbackService.frontDown(pageSize,pageNum,replySort,lookSort,timeSort,title,feedbackStatus);
    }


    /**
     * 查看某个反馈详情（无评论区）
     */
    @GetMapping("/detail")
    @ApiOperation(value = "查看某个反馈详情（无评论区）", notes = "查看某个反馈详情（无评论区）")
    public AjaxResult detail(Long objectId, Integer type) {
        return platformFFeedbackService.detail(objectId, type);
    }

    /**
     * 查询某个帖子下的评论区
     */
    @GetMapping("/commentList")
    @ApiOperation(value = "查询某个帖子下的评论区", notes = "查询某个帖子下的评论区")
    public AjaxResult commentList(Long feedbackId, Integer pageNum, Integer pageSize) {
        return platformFFeedbackService.commentList(feedbackId, pageNum, pageSize);
    }

    /**
     * 发布反馈/评论
     */
    @PostMapping("/addFeedbackOrComment")
    @ApiOperation(value = "发布反馈/评论", notes = "发布反馈/评论")
    public AjaxResult addFeedbackOrComment(@RequestBody PlatformFFeedback platformFFeedback) {
        if (null == platformFFeedback.getTopId()) {
            if (null == platformFFeedback.getTitle() || "".equals(platformFFeedback.getTitle())) {
                return AjaxResult.error("请填写标题");
            }
            if (null == platformFFeedback.getTypeId()) {
                return AjaxResult.error("请选择所属分类");
            }
            if (null == platformFFeedback.getMessage() || "".equals(platformFFeedback.getMessage())) {
                return AjaxResult.error("请填写内容");
            }
            if (null != platformFFeedback.getImageUrl() && "".equals(platformFFeedback.getImageUrl())) {
                String[] split = platformFFeedback.getImageUrl().split(",");
                if (split.length > 9) {
                    return AjaxResult.error("最多添加9张图片");
                }
            }
        } else {
            if (null == platformFFeedback.getMessage() || "".equals(platformFFeedback.getMessage())) {
                return AjaxResult.error("请填写内容");
            }
        }
        return platformFFeedbackService.addFeedbackOrComment(platformFFeedback);
    }

    /**
     * 批量删除反馈/评论
     */
    @DeleteMapping("/deleteFeedbackOrComment/{ids}")
    @ApiOperation(value = "批量删除反馈/评论", notes = "批量删除反馈/评论")
    public AjaxResult deleteFeedbackOrComment(@PathVariable("ids") Long[] ids) {
        return platformFFeedbackService.deleteFeedbackOrComment(ids);
    }

    /**
     * 前台查询我的反馈
     */
    @GetMapping("/myFeedback")
    @ApiOperation(value = "前台查询我的反馈", notes = "前台查询我的反馈")
    public AjaxResult myFeedback(
            Integer pageNum, Integer pageSize, String title, Integer feedbackStatus,
            Long feedbackType, Integer time
    ) {
        return platformFFeedbackService.myFeedback(pageNum, pageSize, title, feedbackStatus, feedbackType, time);
    }

    /**
     * 分页获取和我有关的评论
     */
    @GetMapping("/myFeedbackComment")
    @ApiOperation(value = "分页获取和我有关的评论", notes = "分页获取和我有关的评论")
    public AjaxResult myFeedbackComment(Integer pageNum, Integer pageSize, Integer type) {
        return platformFFeedbackService.myCommentList(pageNum, pageSize, type);
    }

    /**
     * 后台查看所有反馈
     */
    @GetMapping("/backAllFeedback")
    @ApiOperation(value = "后台查看所有反馈", notes = "后台查看所有反馈")
    public AjaxResult backAllFeedback(
            Integer pageNum, Integer pageSize, String title, Integer feedbackStatus,
            Long feedbackType, Integer time
    ) {
        return platformFFeedbackService.backAllFeedback(pageNum, pageSize, title, feedbackStatus, feedbackType, time);
    }

    /**
     * 批量修改反馈
     */
    @PutMapping("/updateFeedback")
    @ApiOperation(value = "批量修改反馈", notes = "批量修改反馈")
    public AjaxResult updateFeedback(@RequestBody List<PlatformFFeedback> platformFFeedbackList) {
        return platformFFeedbackService.updateFeedback(platformFFeedbackList);
    }

    /**
     * 批量删除反馈
     */
    @DeleteMapping("/deleteFeedback/{ids}")
    @ApiOperation(value = "批量删除反馈", notes = "批量删除反馈")
    public AjaxResult deleteFeedback(@PathVariable("ids") Long[] ids) {
        return platformFFeedbackService.deleteFeedback(ids);
    }

    /**
     * 反馈增加浏览量
     */
    @PutMapping("/addLookCount")
    @ApiOperation(value = "反馈增加浏览量", notes = "反馈增加浏览量")
    public AjaxResult addLookCount(Long feedbackId) {
        return platformFFeedbackService.addLookCount(feedbackId);
    }

}

